package org.dppc.fine4j.proxychain.support;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import org.dppc.fine4j.proxychain.MethodCommand;
import org.dppc.fine4j.proxychain.MethodProxyChain;


/**
 * Cglib 支持实现 的 ProxyHandler
 * 
 * @author maomh
 */
public class CGlibProxyHandler extends AbstractProxyHandler implements MethodInterceptor {
	private Class<?> clazz;
	
	public CGlibProxyHandler(Class<?> clazz) {
		this.clazz =clazz;
	}

	
	@Override
	protected boolean checkType(Object object) {
		return clazz.isInstance(object);
	}
	

	@Override
	public Object intercept(Object obj, Method method, Object[] args,
			MethodProxy proxy) throws Throwable {
		MethodCommand command =new MethodCommand(getProxy(), getTarget(), method, args);
		return new MethodProxyChain(methodProxies).doInvoke(command);
	}
}
